#include "file_server.hpp"

DEFINE_bool(mode, false, "0为标准输出，1为文件输出");
DEFINE_string(file_path, "", "文件输出时的文件路径");
DEFINE_int32(level, 0, "日志输出等级，只输出等级>=level的日志");

DEFINE_string(registry_host, "http://127.0.0.1:2379", "服务注册中心地址");
DEFINE_string(base_service, "/service", "服务监控根目录");
DEFINE_string(instance_name, "/file_service/instance", "当前实例名称");
DEFINE_string(access_host, "127.0.0.1:10002", "当前实例的外部访问地址");

DEFINE_int32(listen_port, 10002, "Rpc服务器监听端口");
DEFINE_int32(rpc_timeout, -1, "Rpc调用超时时间");
DEFINE_int32(rpc_threads, 1, "Rpc的IO线程数量");

DEFINE_string(default_storage_path, "./data/", "默认文件存储目录");


int main(int argc, char** argv)
{
    gflags::ParseCommandLineFlags(&argc, &argv, true);
    im::init_logger(FLAGS_mode, FLAGS_file_path, FLAGS_level);

    // 关闭brpc的logging的日志输出
    logging::LoggingSettings settings;
    settings.logging_dest = logging::LoggingDestination::LOG_TO_NONE;
    logging::InitLogging(settings);

    // 1. 初始化好语音服务
    // 2. 初始化brpc服务器
    // 3. 注册键值对
    im::FileServerBuilder fsb;
    fsb.make_rpc_server(FLAGS_listen_port, FLAGS_rpc_timeout, FLAGS_rpc_threads, FLAGS_default_storage_path);
    fsb.make_reg_object(FLAGS_registry_host, FLAGS_base_service + FLAGS_instance_name, FLAGS_access_host);
    auto server = fsb.build();
    server->start();

    return 0;
}